#!/usr/bin/perl
## HTML::TagParser, RSSLite
## HTML::TagParser - Yet another HTML document parser with DOM-like methods
use strict;
use warnings;
use lib qw( ./Lib );
use Encode qw( encode decode );
use Encode::KR;
use URI;
use HTML::TagParser;
use XML::RSS;
use RSSLite;
use CGI;
use Data::Dumper;

my $url = "http://www.soccerline.co.kr/news_list/index.php?menu=main";
my $uri = URI->new( $url );
my $rss = RSSLite->new(version => '1.0', encoding=>"utf-8");
my $cgi = CGI->new();
$cgi->charset('utf-8');

## HTML::TagParser
my $html = HTML::TagParser->new( $url );
my @list = $html->getElementsByTagName( "a" );
my ( $title ) = $html->getElementsByTagName( "title" )->innerText;

$rss->channel(
	title        => $title,
	link         => $url,
	description  => sprintf( "RSS Feed for %s ( %s )", $url, scalar(localtime) ) ,
);

foreach my $item ( @list ) {
	my $attr = $item->attributes;
	my $href = $attr->{'href'};
	my $inner_text =  $item->innerText;
		
	if ( $href =~ m!menu=viewbody! ) {
		$rss->add_item(
			title	=> $inner_text,
			link	=> sprintf ("http://%s%s%s", $uri->host(), $uri->path(), $href),
		);
	}
}

print $cgi->header("text/xml"), $rss->as_string;

